package com.qeado.admin.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.qeado.admin.common.BaseConstData;
import com.qeado.admin.model.UserInfo;
import com.qeado.admin.service.UserInfoService;
import com.qeado.common.helper.AttributeHelper;

@Controller
public class UserInfoController {
	@Autowired
	private UserInfoService userInfoService;
	
	@RequestMapping("/userInfoManage.ac")
    public String userInfoManage(HttpServletRequest request) {
		AttributeHelper.removeSessionAttribute(request, "T_");
        return "admin/user_info_search";
    }
	
	@RequestMapping("/newUser.ac")
	public String newUser(){
		return "admin/user_info_manage";
	}
	
	@RequestMapping("/userSearch.ac")
	public ModelAndView userSearch(HttpServletRequest request, UserInfo userInfo){
		List<UserInfo> userInfoList = userInfoService.userSearch(userInfo);
		request.setAttribute("userInfo", userInfo);
		return new ModelAndView("admin/user_info_search","userInfoList",userInfoList);
	}
	
	@RequestMapping("/saveUser.ac")
	public ModelAndView saveUser(HttpServletRequest request, UserInfo userInfo){
		userInfo.setCreator(request.getSession().getAttribute(BaseConstData.USER_ID).toString());
		String message = userInfoService.saveUser(userInfo);
		return new ModelAndView("admin/user_info_manage","message",message);
	}
	
	@RequestMapping("/selectUser.ac")
	public ModelAndView selectUser(String id){
		UserInfo userInfo = userInfoService.selectUser(id);
		return new ModelAndView("admin/user_info_manage","userInfo",userInfo);
	}
	
	@RequestMapping("/deleteUser.ac")
	public ModelAndView deleteUser(String id){
		userInfoService.deleteUser(id);
		List<UserInfo> userInfoList = userInfoService.userSearch(null);
		return new ModelAndView("admin/user_info_search","userInfoList",userInfoList);
	}
	
	@RequestMapping("/searchUserCompany.ac")
	public ModelAndView searchUserCompany(String type){
		UserInfo userInfo = new UserInfo();
		userInfo.setUserCategory(type);
		return new ModelAndView("admin/user_company_search","userInfo",userInfo);
	}
	
	@RequestMapping("/searchUserCompanyList.ac")
	public ModelAndView searchUserCompanyList(UserInfo userInfo){
		List<UserInfo> companyList = userInfoService.searchUserCompanyList(userInfo);
		return new ModelAndView("admin/user_company_search","companyList",companyList);
	}
}
